import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 强仔
 * Date: 2022-07-23
 * Time: 16:20
 */

public class Main {

    // 1. 年终奖
    // 状态：map[i][j] 表示走到 (i,j) 时，能获得的最大价值
    // 状态转移方程：map[i][j] = max(map[i - 1][j], map[i][j - 1]) + board[i][j]
    // 初始状态：map[i][0] = 累加和, map[0][j] = 累加和
    // 得到结果：map[5][5]
    public int getMost(int[][] board) {
        for (int i = 1; i < 6; i++) {
            board[i][0] += board[i - 1][0];
        }
        for (int i = 1; i < 6; i++) {
            board[0][i] += board[0][i - 1];
        }
        for (int i = 1; i < 6; i++) {
            for (int j = 1; j < 6; j++) {
                board[i][j] = Math.max(board[i - 1][j], board[i][j - 1]) + board[i][j];
            }
        }
        return board[5][5];
    }


    static class Pos{
        int x;
        int y;
        public Pos(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int[][] nextP = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

    // 2. 迷宫问题
    // DFS
    // BFS 我用不了
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int row = scanner.nextInt();
        int col = scanner.nextInt();
        int[][] map = new int[row][col];


        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                map[i][j] = scanner.nextInt();
            }
        }

        boolean[][] book = new boolean[row][col];
        List<Pos> results = DFS(map, row, col, new ArrayList<>(), book, 0, 0);

        for (Pos pos : results) {
            System.out.println("(" + pos.x + "," + pos.y + ")");
        }
    }

    public static List<Pos> DFS(int[][] map, int row, int col, List<Pos> results, boolean[][] book, int x, int y){
        if(x < 0 || x >= row || y < 0 || y >= col || book[x][y]){
            return results;
        }

        if(map[x][y] == 1){
            return results;
        }

        results.add(new Pos(x, y));
        book[x][y] = true;

        if(x == row - 1 && y == col - 1){
            return results;
        }

        for (int[] next : nextP) {
            int newX = x + next[0];
            int newY = y + next[1];
            DFS(map, row, col, results, book, newX, newY);
            if(book[row - 1][col - 1]){
                break;
            }
        }

        if(!book[row - 1][col - 1]){
            results.remove(results.size() - 1);
        }
        return results;
    }
}
